package com.example.roadship;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ScheduleReceiver extends BroadcastReceiver {
	  private static final long REPEAT_TIME = 1000 * 30;
	  @Override
	  public void onReceive(Context context, Intent intent) {
		  if( "android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
			  AlarmManager service = (AlarmManager) context
				        .getSystemService(Context.ALARM_SERVICE);
				    Intent i = new Intent(context, RequestReceiver.class);
				    PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,0);
				    Calendar calendar = Calendar.getInstance();
		            calendar.setTimeInMillis(System.currentTimeMillis());
		            calendar.add(Calendar.SECOND, 10);
				    //Start 50 seconds after boot completed
				    //cal.add(Calendar.SECOND, 50);
				    service.setInexactRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), REPEAT_TIME, pending);
		  }
	  }
}
